home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
9-Digit Zip Code Directory
/
9-Digit Zip Code Directory (American Business Information) (ABIZIP-12).ISO
/
z4src.zip
/
Z4PFWRK.C
< prev
next >
Wrap
C/C++ Source or Header
|
1995-07-29
|
7KB
|
256 lines
//----------------------------------------------------------------------------
// MODULE DESCRIPTION
//
// Module: z4pfwrk.c
// Title: 9-Digit ZIP Code Directory -- on CD-ROM
// Notice: John M. Weeder
// Copyright (c) 1993. All rights reserved.
// This module contains proprietary information and should be
// treated as confidential.
//
//----------------------------------------------------------------------------
// MAINTENANCE HISTORY
//
// $Workfile$
// $Revision$
// $Author$
// $Date$
// $Log$
//
//----------------------------------------------------------------------------
// MODULE NARRATIVE
//
// This module contains the program entry point for
//
// The code in this module may be written in C++ or C.
//
// This module is portable to:
// DOS 3.X+
// MS Windows 3.X+
// OS/2 2.X+
// OS/2 2.0 PM
//
// The following compilers are supported:
// MSC 6.0A
// MSC/C++ 7.0
// Borland C++ 3.1 for DOS
// Borland C++ 1.0 for OS/2 2.X
//
//----------------------------------------------------------------------------
#include <z4.h>
//----------------------------------------------------------------------------
// Stack size
//----------------------------------------------------------------------------
#if COMPILER_BORLAND && (OS_DOS || OS_WINDOWS)
unsigned _stklen = 0x4000;
#endif
//----------------------------------------------------------------------------
// Globals
//----------------------------------------------------------------------------
//
// A useless string which is simply embedded in the executable.
//
PSZ __pszCredits__ = "Written by John M Weeder, 1993";
//
// This should contain a program description which will be displayed as
// part of the program's help text.
//
static PCSZ pcszDescription =
"This program generates the batch and script files used for the file\n"
"build.";
//
// Program command line options
//
static BS_CMDOPT acmdopt[] =
{
BS_CMDOPT_NULL,
};
//----------------------------------------------------------------------------
// Description: main() - Program entry point
// Parameters: Standard C parameters
// Returns: DOS return code.
//----------------------------------------------------------------------------
int main(int argc, char **argv)
{
static BS_CFG cfg = CFG_DFT;
int retval = 99;
CHAR szName[MAX_PATH];
SIZET cb;
PBYTE pb = NULL;
FLAG16 fs;
LONG lSize;
PBYTE pbRec;
HF hf = -1;
HF hfDos = -1;
HF hfUnix = -1;
BOOL fFirst = TRUE;
SIZET cRec = 0;
SIZET cScript = 0;
CHAR szZip3[4], szFinance[7];
CHAR szFormat[160];
//
// Initialize base library
//
BaseLibraryInitialize(argc, argv, &cfg);
BaseTitle("$Revision: 93.1 $", __DATE__, __TIME__, "9-Digit ZIP Disc Batch/Script File Build");
if (!BaseTitleHelp(acmdopt, pcszDescription,NULL))
return 99;
//
// Read entire PF file
//
strcpy(szName, "z4pf.inp"); // Open file
FnameQualify(szName, NULL, EnvGet("DATA"), 0);
fs = FL_OPEN|FL_READONLY|FL_BINARY;
if (!FileOpen(&hf, szName, fs, NULL))
goto ERROR_EXIT;
lSize = FileGetSize(hf); // Get size
if (lSize <= 0 || lSize > 30000)
goto ERROR_EXIT;
cb = (SIZET)lSize; // Allocate buffer
pb = MemAlloc(cb + 1);
if (pb == NULL)
goto ERROR_EXIT;
if (!FileRead(hf, pb, cb, 0L)) // Read file
goto ERROR_EXIT;
pb[cb] = '\0'; // Add a null terminator!
FileClose(hf); // Close file
hf = -1;
//
// Process POF file
//
pbRec = pb;
szFinance[0] = '\0';
while (*pbRec)
{
//
// Open new input files if needed!!
//
if ((fFirst && cRec == 0)
|| (fFirst && cRec == 25)
|| (!fFirst && cRec == 50))
{
cScript++;
if (hfDos >= 0) // Close existing files
{
FileClose(hfDos);
hfDos = -1;
}
if (hfUnix >= 0)
{
sprintf(szFormat,
"\r\n"
"z4pfutil /work /split /u=%s\r\n"
"z4z4bld /compress\r\n",
szFinance);
if (!FileWrite(hfUnix, szFormat, strlen(szFormat), -1L))
goto ERROR_EXIT;
FileClose(hfUnix);
hfUnix = -1;
}
// Open DOS batch file
sprintf(szName, "DOS%u.BAT", cScript);
FnameQualify(szName, "BAT", EnvGet("DATA"), 0);
fs = FL_CREATE|FL_TRUNCATE|FL_READWRITE|FL_DENYREADWRITE|FL_BINARY;
if (!FileOpen(&hfDos, szName, fs, NULL))
goto ERROR_EXIT;
// Open unix script
sprintf(szName, "unix%u", cScript);
FnameQualify(szName, NULL, EnvGet("DATA"), 0);
fs = FL_CREATE|FL_TRUNCATE|FL_READWRITE|FL_DENYREADWRITE|FL_BINARY;
if (!FileOpen(&hfUnix, szName, fs, NULL))
goto ERROR_EXIT;
if (cRec)
{
fFirst = FALSE;
cRec = 0;
}
}
cRec++;
//
// Extract data from record
//
memcpy(szZip3, pbRec, 3);
szZip3[3] = '\0';
memcpy(szFinance, pbRec + 4, 6);
szFinance[6] = '\0';
if (strcmp(szZip3, "901") == 0) // No data for this ZIP3
goto SKIP_RECORD;
//
// Output data
//
sprintf(szFormat,
"pkunzip -n f:\\zip4\\%s\r\n"
"if not exist %s.txt (echo %s.txt not created ^ echo %s.txt not created >> c:\\zip4\\error ^ quit)\r\n"
"\r\n",
szZip3, szZip3, szZip3, szZip3);
if (!FileWrite(hfDos, szFormat, strlen(szFormat), -1L))
goto ERROR_EXIT;
sprintf(szFormat,
"z4pfsplt /delete %s.txt\r\n",
szZip3);
if (!FileWrite(hfUnix, szFormat, strlen(szFormat), -1L))
goto ERROR_EXIT;
//
// Move to start of next record
//
SKIP_RECORD:
while (*pbRec && *pbRec != '\n')
pbRec++;
while (*pbRec && (*pbRec == '\n' || *pbRec == '\r' || *pbRec == '\x1A'))
pbRec++;
}
if (hfUnix >= 0)
{
strcpy(szFormat,
"\r\n"
"z4pfutil /work /split /p=30000\r\n"
"z4z4bld /compress\r\n");
if (!FileWrite(hfUnix, szFormat, strlen(szFormat), -1L))
goto ERROR_EXIT;
}
retval = 0;
ERROR_EXIT:
if (pb)
MemFree(pb);
if (hf >= 0)
FileClose(hf);
if (hfDos >= 0)
FileClose(hfDos);
if (hfUnix >= 0)
FileClose(hfUnix);
return retval;
}
//----------------------------------------------------------------------------
//------------------------------- End of File --------------------------------
//----------------------------------------------------------------------------